package day8;

import java.io.File;
import java.io.FileInputStream;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class ShowFile {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入一个目录：");
        String name = sc.next();
        ShowFile t = new ShowFile();
        File f = new File(name);
        //t.display(f);
        t.reverseFile(f);
    }
    public void reverseFile(File f){
        LinkedList<File> list=new LinkedList<>();
        list.add(f);
        while (list.isEmpty()==false){
            File temp=list.removeFirst();//删除并获得第一个
            System.out.println(temp);
            File[] files = temp.listFiles();
            if(files==null||files.length<1)
                continue;
            for(int i=files.length-1;i>=0;i--)
                list.addFirst(files[i]);

//            for(File file:files)
//                list.addFirst(file);
        }
    }
    public  void display(File ff){
        System.out.println(ff);
        if (!ff.isFile()){
            File[] files = ff.listFiles();
            for (File file : files) {
                display(file);
            }
        }
    }
}
